/**
 * 主界面的js样式,全局方法一般放在这里
 *
 * @author johnny
 * @date 2018/12/8
 */

var parseParam = function(param, key) {
    var paramStr = "";
    if (param instanceof String || param instanceof Number || param instanceof Boolean) {
        paramStr += "&" + key + "=" + param;
    } else {
        $.each(param, function(i) {
            var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
            paramStr += '&' + parseParam(this, k);
        });
    }
    return paramStr.substr(1);
};

var fmid = "fhindex";	//菜单点中状态
var mid = "fhindex";	//菜单点中状态

//用于在内容页弹出新tab
//param请求的参数,因为在url后拼接,所以需要考虑参数大小
function addTab(id,fid,name,url,param){
    if(id != mid){
        $("#"+mid).removeClass();
        mid = id;
    }
    if(fid != fmid){
        $("#"+fmid).removeClass();
        fmid = fid;
    }
    $("#"+fid).attr("class","active open");
    $("#"+id).attr("class","active");
    if(param!=null){
        var urlParam="";
        //var param = JSON.parse(param);
        console.log(param);

        for(var key in param){
            // ?test=1&test2=2
            // if(i==0){
            //     urlParam += key+"="+param[key];
            //     alert(urlParam);
            // }else{
            //     urlParam += "&"+key+"="+param[key];
            //     alert(urlParam);
            // }
            urlParam += "&"+key+"="+param[key];
        }
        // 去掉第一个&
        urlParam = urlParam.substr(1);

        if(url.indexOf("?")== -1){
            url+="?"+urlParam;
        }else{
            url+="&"+urlParam;
        }
    }
    console.log(url);
    top.mainFrame.tabAddHandler(id,name,url);
    if(url != "druid/index.html"){
        jzts();
    }
}

//清除加载进度
function hangge(){
    $("#jzts").hide();
}

//显示加载进度
function jzts(){
    $("#jzts").show();
}